package menuService

import (
	"fmt"
	menuDto "news_for_deepseek_interface/dto/admin/system/menu"
	"news_for_deepseek_interface/model"
	adminModel "news_for_deepseek_interface/model/admin"
)

// 获取所有菜单
func GetAllMenu() (response []menuDto.GetAllMenuResponse, err error) {

	var adminAuthRuleData []adminModel.AdminAuthRuleStruct
	if err = model.
		GetInstance().
		GetDB().
		Model(&adminModel.AdminAuthRuleStruct{}).
		Where("show_link = ?", 1).
		Find(&adminAuthRuleData).Error; err != nil {
		err = fmt.Errorf("获取菜单失败: %v", err)
		return
	}

	for _, v := range adminAuthRuleData {
		response = append(response, menuDto.GetAllMenuResponse{
			Id:       v.Id,
			Title:    v.Title,
			MenuType: 0,
			ParentId: v.ParentId,
		})
	}

	return response, nil
}
